package com.ikun.service.impl;

import com.ikun.mapper.TbCommentMapper;
import com.ikun.pojo.TbComment;
import com.ikun.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    TbCommentMapper commentMapper;

    @Override
    public List<TbComment> selMyComment(int userid, int page) {
        int pg = (page-1)*8;
        List<TbComment> commentList = commentMapper.selMyComment(userid,pg);
        return commentList;
    }

    @Override
    public int selMyCommentCount(int userid) {
        int count = commentMapper.selMyCommentCount(userid);
        if (count <= 8){
            count = 1;
        }else{
            if (count%8 == 0){
                count = count/8;
            }else{
                count = count/8+1;
            }
        }
        return count;
    }

    @Override
    public List<TbComment> selComment(int taskid) {
        List<TbComment> tbComments = commentMapper.selComment(taskid);
        return tbComments;
    }

    @Override
    public int addComment(TbComment tbComment) {
        int count = commentMapper.addComment(tbComment);
        return count;
    }
}
